package erp.education.web.action.user.transaction;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ModelDriven;

import erp.education.client.user.transaction.LoginRequest;
import erp.education.server.beans.interfaces.user.transaction.LoginServiceI;
import erp.education.web.common.BaseAction;

public class LoginAction extends BaseAction implements ModelDriven<LoginRequest>{
@Autowired
 LoginRequest loginRequest;
@Autowired
LoginServiceI loginService;
public String login() throws Exception{
		
		return "inValidSession";
	}
public String homePage()throws Exception{
	if(null!=getSession().getAttribute("user")){
	return "homePage";
	}
	
	return "inValidSession";
	
}

public String logout()throws Exception{
	getSession().invalidate();
	
	return "inValidSession";
	
}
	public String validateLogin()throws Exception{
		
		this.result=loginService.validateLoginService(loginRequest).getResponseObject();
	 
		if(!(this.result.getResultList().isEmpty())){
 
			getSession().setAttribute("user", this.result.getResultList().get(0));
			 
			getSession().setAttribute("cssView",this.result.getResultList().get(1));
			return "validSession";
		} 
		return "inValidSession";
	}
public String updateUserTheme() throws Exception{
	Map<String,Object> userInfo=new HashMap<String, Object>();
	userInfo.put("user", getSession().getAttribute("user"));
	loginRequest.setUserInfo(userInfo);
	this.result=loginService.updateTheme(loginRequest).getResponseObject();
	getSession().setAttribute("user", this.result.getResultList().get(0));
	getSession().setAttribute("cssView",this.result.getResultList().get(1));
	return "messageView";
}
	@Override
	public LoginRequest getModel() {
		// TODO Auto-generated method stub
		return this.loginRequest;
	}
	
}
